<?php
	
	$imgid   = escapestr($_REQUEST['photo_id']);
	
	if($_REQUEST['edit']) {
		$title    = escapestr($_REQUEST['title']);
		$access   = escapestr($_REQUEST['access']);
		if ($_REQUEST['external']) $external = 1; else $external = 0;
		$type     = escapestr($_REQUEST['type']);
		
		$query = " UPDATE `photos` SET 	`title`		='$title', 
										`access`	='$access', 
										`external` 	='$external',
										`type`		='$type'
					WHERE `id`='$imgid'";
		$result = mysql_query($query);
		if ($result) {
			$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_photos"),GetLangString($lang,"msg_photoupdated"));
		} else {	
			$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_error"),GetLangString($lang,"msg_dberror"));
		}		
			
	}



	
	if (isset($_REQUEST['size'])) {
		$imgsize = escapestr($_REQUEST['size']);
	} else {
		$imgsize = 0;
	}
 	
	$query   = "select * from photos where id=$imgid" ;
	$result  = mysql_query($query);
	 
	if ($imgdata = mysql_fetch_array($result)) {

 		$ownerid  = $imgdata['owner'];
		$query2   = "select `name` from `users` where `id`='$ownerid'" ;
		$result2  = mysql_query($query2);
		$owner    = mysql_result($result2,0);
		$time = date("d-m-Y H:i:s",$imgdata['time']);
		$query2 = "select sum(`count`) from `photostats` where `photo`='$imgid'";
		$result2 = mysql_query($query2);
		$count = mysql_result($result2,0);
		


 //str_ireplace("%name%","<b>$profile_name</b>",GetLangString($lang,"txt_lookingat")), $infotxt);

		// langstring!!
		if ($RENDER_MOBILE) $imgsize = 150; else $imgsize = 450;
		if (!$RENDER_MOBILE) $photo   .= " <table width='100%'><tr><td width='50%' valign='top'>";
		$photo   .=FormatElementTime( $imgdata['title'], $time . " ".  GetLangString($lang,"txt_by") ." <a href='index.php?do=profile&profile_id=$ownerid'>". $owner ."</a> - ". str_ireplace("%count%", (int)$count ,GetLangString($lang,"txt_viewcount")) ,
//Viewed ".(int)$count." times","
		"<center><a target='_blank' href='index.php?do=getphoto&id=".$imgdata['id']."'>
		<img border=\"0\" src=\"index.php?do=getphoto&size=$imgsize&id=".
								$imgdata['id']."\" title=\"".	$imgdata['title']."\"></a></center>");
								if (!$RENDER_MOBILE) $photo.="</td><td valign='top'>";
								
								
		if (!$RENDER_MOBILE and $imgdata['external']==0) $photo .= FormatElement(GetLangString($lang,"txt_photolinks"),
				"<center><table width='75%'><tr><td>".
				GetLangString($lang,"txt_photourl")."
				<textarea rows=2>$SITE_URL/index.php?do=viewphoto&photo_id=$imgid</textarea>".
				GetLangString($lang,"txt_photodirecturl")."
				<textarea  rows=2>$SITE_URL/index.php?do=getphoto&size=400&id=$imgid</textarea>".
				GetLangString($lang,"txt_photohtmlurl")."
				<textarea  rows=2>".htmlentities("<a href='$SITE_URL/index.php?do=viewphoto&photo_id=$imgid'>".
				"<img src='$SITE_URL/index.php?do=getphoto&size=400&id=$imgid'></a>")."</textarea>".
				GetLangString($lang,"txt_photobburl")."
				<textarea rows=2>[img]$SITE_URL/index.php?do=getphoto&size=400&id=".$imgid."[/img]</textarea>
				</tr></td></table></center>");		

		
		if ($id == $ownerid ){
			if($imgdata['external']==1) $external = 'checked';
			if ($imgdata['access']==0) $acc0='selected';
			if ($imgdata['access']==1) $acc1='selected';
			if ($imgdata['access']==2) $acc2='selected';
			
			if ($imgdata['type']==0) $type0='selected';
			if ($imgdata['type']==1) $type1='selected';
			if ($imgdata['type']==2) $type2='selected';
			if ($imgdata['type']==3) $type3='selected';
			if ($imgdata['type']==4) $type4='selected';
			if ($imgdata['type']==5) $type5='selected';
			if ($imgdata['type']==6) $type6='selected';
			if ($imgdata['type']==7) $type7='selected';
			if ($imgdata['type']==8) $type8='selected';
			if ($imgdata['type']==9) $type9='selected';
			if ($imgdata['type']==10)$typeA='selected';
			
			$photo .= FormatElement(GetLangString($lang,"txt_photoedit"),
			
			
			
			"<center><table width='75%'><tr><td>
			<form method='post' action='index.php?do=viewphoto&photo_id=$imgid'>
		
		".GetLangString($lang,"txt_phototitle")."</td>
		<td><input type=\"text\" name=\"title\"/ value='".$imgdata['title']."'></td></tr><tr>
		
		<td>".GetLangString($lang,"txt_photoaccess")."</td>       
		<td><select name=\"access\" size=\"1\">
		<option value=\"0\"  $acc0>".GetLangString($lang,"txt_public")."</option>
		<option value=\"1\"	 $acc1>".GetLangString($lang,"txt_friends")."</option>
		<option value=\"2\"	 $acc2>".GetLangString($lang,"txt_private")."</option>		
		</select>"."</td></tr><tr>
		
		<td>".GetLangString($lang,"txt_photorestrict")."</td>
		<td><input type='checkbox'  $external name='external'></td></tr>
					   
		<td>".GetLangString($lang,"txt_phototype")."</td><td><select name=\"type\" size=\"1\">
		<option value=\"0\" $type0			>".GetLangString($lang,"txt_na")."</option>
		<option value=\"1\" $type1			>".GetLangString($lang,"txt_photo_you")."</option>
		<option value=\"2\"	$type2		 	>".GetLangString($lang,"txt_photo_people_you")."</option>
		<option value=\"3\" $type3			>".GetLangString($lang,"txt_photo_people_other")."</option>		
		<option value=\"4\" $type4			>".GetLangString($lang,"txt_photo_no-people")."</option>		
		<option value=\"5\" $type5			>".GetLangString($lang,"txt_art_drawing")."</option>		
		<option value=\"6\" $type6			>".GetLangString($lang,"txt_art_painting")."</option>		
		<option value=\"7\" $type7  		>".GetLangString($lang,"txt_art_other")."</option>		
		<option value=\"8\" $type8				>".GetLangString($lang,"txt_art_digital_pixel")."</option>		
		<option value=\"9\" $type9				>".GetLangString($lang,"txt_art_digital_vector")."</option>		
		<option value=\"10\"	$typeA			>".GetLangString($lang,"txt_art_digital_other")."</option>		
		</select>"."</td></tr>
		<td colspan=2><input type=Submit Value=".GetLangString($lang,"txt_save")." Name=edit>
		</form>
		<form method=post action=index.php?do=photomanager>
			<input type=hidden name=delete value=$imgid>
			<input type=submit value=".GetLangString($lang, "txt_delete").">
		</form>
		<form method=post action=index.php?do=photomanager>
		<input type=hidden name=profilepic value=$imgid>
			<input type=submit value='".GetLangString($lang, "txt_setprofilepic")."'>
		</form>
		</td></tr></table></center>");
		
		
		}
		$photo .= "</table>";
		
	    
		
	    //$SITE_MIDDLE .=  FormatElementTime( $imgdata['title'], $time ." by <a href='index.php?do=profile&profile_id=$ownerid'>". $owner ."</a>" ,$photo ) ;
		// GetLangString voor 'by'
//		$SITE_MIDDLE .= FormatElement  ( $imgdata['title'], $photo ) ;
		$SITE_MIDDLE .= $photo;
		if ($id) 
			include ("photocomments.php") ;
		else
			$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_comments"),GetLangString($lang,"txt_pleaselogin"));
			

	} else {
		$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_err"),GetLangString($lang,"msg_photonotfound")); 
	}
?>
